import 'package:get/get.dart';
import 'package:banquanjie_app/app/services/HttpsRequest.dart';
class HomeController extends GetxController {
  //TODO: Implement HomeController
  RxList bannerList = [].obs;
  RxList workList = [].obs;
  RxList eliteList = [].obs;
  RxList companyList = [].obs;
  RxList projectList = [].obs;
  List bannerList2 = [
    { "title": "经典IP", "img": "https://zsjl.oss-cn-beijing.aliyuncs.com/test/xcx/home_work.png", 'onLink': '/work-list' },
    { "title": "IP项目", "img": "https://zsjl.oss-cn-beijing.aliyuncs.com/test/xcx/home_project.png", 'onLink': '/project-list' },
    { "title": "品牌公司", "img": "https://zsjl.oss-cn-beijing.aliyuncs.com/test/xcx/home_company.png", 'onLink': '/company-list' },
    { "title": "IP精英", "img": "https://zsjl.oss-cn-beijing.aliyuncs.com/test/xcx/home_ipElite.png", 'onLink': '/ip-elite' },
    { "title": "精准推送", "img": "https://zsjl.oss-cn-beijing.aliyuncs.com/test/xcx/home_push.png" },
  ];
  List uploadList = [
    {
      "title": '我要发布作品变现',
      "title_desc": '1023人已发布',
      "desc": '经纪人快速对接，交易安全有保障',
      "avatar": ['avatar2', 'avatar1'],
      "btn_txt": '立即发布作品',
      "bg_img": "https://zsjl.oss-cn-beijing.aliyuncs.com/test/xcx/home_upload1.png",
      "link": '/subPackages/publish/works/index'
    },
    {
      "title": '我要采购作品',
      "title_desc": '1023人已使用',
      "desc": '平台版权链审核，作品真实优质',
      "avatar": ['avatar2', 'avatar3'],
      "btn_txt": '立即采购作品',
      "bg_img": "https://zsjl.oss-cn-beijing.aliyuncs.com/test/xcx/home_upload2.png",
      "link": '/subPackages/publish/works/publishCollect'
    },
    {
      "title": '我要寻找商务合作',
      "title_desc": '1023人已注册发布',
      "desc": '发布代表作品展示个人才艺，让更多人看到您!',
      "avatar": ['avatar4', 'avatar5'],
      "btn_txt": '立即代表作品',  
      "bg_img": "https://zsjl.oss-cn-beijing.aliyuncs.com/test/xcx/home_upload3.png",
      "link": '/subPackages/publish/ipElite/publishRepWork'
    },
    {
      "title": '版全界延揽精英',
      "title_desc": '821人已使用',
      "desc": '821位精英在线，找人才就是方便',
      "avatar": ['avatar5', 'avatar6'],
      "btn_txt": '立即延揽精英',
      "bg_img": "https://zsjl.oss-cn-beijing.aliyuncs.com/test/xcx/home_upload4.png",
      "link": '/subPackages/publish/ipElite/publishRecruit'
    },
    {
      "title": '我要发布作品项目',
      "title_desc": '821人已发布',
      "desc": '项目实现更容易',
      "avatar": ['avatar7', 'avatar8'],
      "btn_txt": '立即发布作品项目',
      "bg_img": "https://zsjl.oss-cn-beijing.aliyuncs.com/test/xcx/home_upload5.png",
      "link": '/subPackages/publish/project/index'
    },
    {
      "title": '我要资金找项目',
      "title_desc": '236人已使用',
      "desc": '专业影投人对接，为您挑选最优质项目',
      "avatar": ['avatar9', 'avatar10'],
      "btn_txt": '立即征集项目',
      "bg_img": "https://zsjl.oss-cn-beijing.aliyuncs.com/test/xcx/home_upload6.png",
      "link": '/subPackages/publish/project/publishCollect'
    }
  ];
  HttpsClient httpsClient = HttpsClient();

  @override
  void onInit() {
    super.onInit();
    getBannerList();
    getWorkList();
    getEliteList();
    getCompanyList();
    getProjectList();
  }

  @override
  void onReady() {
    super.onReady();
  }

  @override
  void onClose() {
    super.onClose();
  }

  void getBannerList() async {
    var res = await httpsClient.post('user/banner/show', { "bannerPosition": 1, "pageSize":100 });
    var result = res.data;
    if (result['code'] == 200) {
      bannerList.value = result['data']['rows'];
      update();
    }
  }

  void getWorkList() async {
    var res = await httpsClient.post('works/works/ip/list', { "pageNum": 1, "pageSize": 4, "showDrama": 1 });
    var result = res.data;
    if (result['code'] == 200) {
      workList.value = result['data']['rows'];
      update();
    }
  }

  void getEliteList() async {
    var res = await httpsClient.post('user/up/ipEliteList', { "ipDirection": 939, "pageCode": 1, "pageSize": 4 });
    var result = res.data;
    if (result['code'] == 200) {
      eliteList.value = result['data']['rows'];
      update();
    }
  }
  void getCompanyList() async {
    var res = await httpsClient.post('user/up/brandList', { "pageCode": 1, "pageSize": 4 });
    var result = res.data;
    if (result['code'] == 200) {
      companyList.value = result['data']['rows'];
      update();
    }
  }
  // getProjectList  proList /project/pro/ip/list
  void getProjectList() async {
    var res = await httpsClient.post('project/pro/ip/list', { "pageNum": 1, "pageSize": 4 });
    var result = res.data;
    if (result['code'] == 200) {
      projectList.value = result['data']['rows'];
      update();
    }
  }
}
